﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using BusinessLayer;
using System.Windows.Forms;

namespace Design
{
    public partial class WebForm18 : System.Web.UI.Page
    {
        MembershipUser objmember = Membership.GetUser();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (User.Identity.IsAuthenticated)
            {
                txtUsername.Text = objmember.UserName;

                Add_Users_Profile pro = new Add_Users_Profile();
                List<Add_Users_Profile> objItems = new List<Add_Users_Profile>();
                objItems = pro.getuser_info();

                int count = objItems.Count();
                for (int i = 0; i < count; i++)
                {
                    if (objmember.ProviderUserKey.ToString().ToUpper() == objItems[i].userid)
                    {
                        try
                        {
                            txtIDNumber.Text = objItems[i].identity;
                            txtFirstName.Text = objItems[i].fname;
                            txtLastName.Text = objItems[i].lname;
                            txtContactNo.Text = objItems[i].contact;
                            txtAddress.Text = objItems[i].address;
                        }
                        catch
                        {

                        }
                    }
                }
            }
            else
            {
                Response.Redirect("~/Login.aspx");
                txtIDNumber.Text = "";
                txtFirstName.Text = "";
                txtLastName.Text = "";
                txtContactNo.Text = "";
                txtAddress.Text = "";
                txtUsername.Text = "";
            }
        }

        protected void btnSaveDetails_Click(object sender, EventArgs e)
        {
            try
            {
                Add_Users_Profile objadd = new Add_Users_Profile();

                objadd.userid = objmember.ProviderUserKey.ToString().ToUpper();
                objadd.username = txtUsername.Text;
                objadd.identity = txtIDNumber.Text;
                objadd.fname = txtFirstName.Text;
                objadd.lname = txtLastName.Text;
                objadd.contact = txtContactNo.Text;
                objadd.address = txtAddress.Text;

                objadd.add_users_pro();

                MessageBox.Show("Profile Added", "Profile", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch
            {

            }
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            Add_Users_Profile objupdate = new Add_Users_Profile();
            objupdate.userid = objmember.ProviderUserKey.ToString().ToUpper();
            objupdate.identity = txtIDNumber.Text;
            objupdate.fname = txtFirstName.Text;
            objupdate.lname = txtLastName.Text;
            objupdate.contact = txtContactNo.Text;
            objupdate.address = txtAddress.Text;

            objupdate.update_user_profile();
        }
    }
}